package applet.molecule;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JPanel;

@SuppressWarnings("serial")
public class DspPanel extends JPanel {
	
	public static final int SIZE = 100;

	private DspButton dspButton;
	
	private boolean isGroup;
	
	public DspPanel(boolean isGroup, int index){
		this.isGroup = isGroup;
		
		dspButton = new DspButton(index);
		locateButton();
	}
	
	private void locateButton(){
		dspButton.setPreferredSize(new Dimension(DspButton.SIZE, DspButton.SIZE));
		add(dspButton);
		dspButton.setLocation(0, 12);
	}
	
	public DspButton getButton(){
		return dspButton;
	}
	
	public void paint(Graphics g){
		super.paint(g);
		
		if (isGroup) {
			final int rectSize = DspButton.SIZE - 1;

			g.setColor(Color.BLACK);

			// outer
			g.drawLine(14, 3, 14, 0);
			g.drawLine(14, 0, rectSize + 12, 0);
			g.drawLine(rectSize + 12, 0, rectSize + 12, rectSize - 2);
			g.drawLine(rectSize + 12, rectSize - 2, rectSize + 9, rectSize - 2);

			// internal
			g.drawLine(11, 6, 11, 3);
			g.drawLine(11, 3, rectSize + 9, 3);
			g.drawLine(rectSize + 9, 3, rectSize + 9, rectSize + 1);
			g.drawLine(rectSize + 9, rectSize + 1, rectSize + 6, rectSize + 1);
		}
	}
}
